import { ChangeEvent } from "react";

// input-受控组件
interface ControlledProps {
  value?: string;
  onChange: (value: string | undefined) => void;
}
export default function Controlled(props: ControlledProps) {
  const { value, onChange } = props;
  function handleChange(e: ChangeEvent<HTMLInputElement>) {
    onChange(e.target.value);
  }
  return (
    <>
      <input type="text" onChange={(e) => handleChange(e)} value={value} />
    </>
  );
}
